import router from './router'

router.beforeEach((to, from, next) => {
    console.log("this is the interceptor in the front end..........");
    console.log("from the path => ", from);
    console.log("go to the path => ", to);
    console.log("the router => ", router);
    if(to.matched.length == 0){
        return next({ path: '/page404' });
    }

    // set the page title
    let titleList = to.matched.map(route => route.meta.title).filter(title => !!title);
    window.document.title = titleList.join('-');

    if (['/login','/page404','/page403'].some(path => path === to.path)) {
        return next();
    }

    if (!sessionStorage.getItem('loginedFlag')) {
        return next({ path: '/login' });
    }

    return next();
});